// Copyright 2018 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.

package gtype

import (
    "sync/atomic"
)

type Uint struct {
    val uint64
}

func NewUint(value...uint) *Uint {
    if len(value) > 0 {
        return &Uint{val:uint64(value[0])}
    }
    return &Uint{}
}

func (t *Uint) Clone() *Uint {
    return NewUint(t.Val())
}

func (t *Uint) Set(value uint) (old uint) {
    return uint(atomic.SwapUint64(&t.val, uint64(value)))
}

func (t *Uint) Val() uint {
    return uint(atomic.LoadUint64(&t.val))
}

func (t *Uint) Add(delta uint) int {
    return int(atomic.AddUint64(&t.val, uint64(delta)))
}